import { stringToBytes } from "../../utils/weichatPb/src/util";
let calendar;
// Componet/Componet.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    typeList: {
      type: Array,
    },
    typeName:{
        type:String
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    filterIndex:0,
    cityShow: '0',
    provIndex: 0,
    cityIndex: 0,
    monthIndex: 0,
    userId:null,
    // userName: '师傅',
    month_animationData: {},
    type_animationData: {},
    startDate: null,
    endDate: null
  },
  /**
   * 组件的方法列表
   */
  methods: {　　　 //option的显示与否
    onDisplay() {
      if (!calendar) {
        calendar = this.selectComponent("#calendar")
      }
      calendar.show()
    },
    dateChange(e) {
      console.log(e);
      this.setData({
        startDate: e.detail.startDate,
        endDate: e.detail.endDate,
      })
    },
    inputName: function (e) {
      clearTimeout(this.data.timer)
      // let inputName = e.detail.value
      this.data.timer = setTimeout(() => {
        console.log(e.detail.value)
        this.setData({
          inputName: e.detail.value
        })
      }, 500);
      // this.setData({
      //   timer: timer
      // })
    },
    /**
     * 附加筛选条件变化
     */
    pickerChange:function (e) {
      let filterIndex = e.detail.value;
      this.setData({
        filterIndex: filterIndex,
        inputName:''
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.monthId];
      this.triggerEvent('filterevent', {idArray:idArray,filterIndex:filterIndex});
    },
    searchHospital:function(){
      let that = this;
      that.setData({
        provName: '省',
        cityName: '市',
        filterIndex:0,
      })
      if (that.data.provId != 0 || that.data.cityId != 0 ) {
        that.setData({
          provId: 0,
          cityId: 0,
        })
      }
      if(!that.data.inputName){
        let idArray = [that.data.provId, that.data.cityId, that.data.monthId,that.data.phone,that.data.userId]
        that.triggerEvent('myevent', idArray)
      }else {
        that.triggerEvent('searchevent', that.data.inputName)
      }
    },
    focusEvent: function(){
      this.cancelSelect()
    },
    userToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='4') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '4',
        })
      }
      this.setData({
        type_animationData: this.animation.export()
      })
    },
    provToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='1') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '1',
        })
      }
      this.setData({
        prov_animationData: this.animation.export()
      })
    },
    cityToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='2') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '2',
        })
      }
      this.setData({
        city_animationData: this.animation.export()
      })
    },
    monthToggle: function() {
      this.pickUp()
      if (this.data.cityShow == '3') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '3',
        })
      }
      this.setData({
        month_animationData: this.animation.export()
      })
    },
    //创建动画

    toggleAnimation: function(angle) {
      var animation = wx.createAnimation({
        timingFunction: "ease"
      })
      this.animation = animation;
      animation.rotate(angle).step()
    },
    
    setUser:function (e) {
      console.log("setUser-->",e)
     
      let userIndex = e.target.dataset.index; //当前点击的索引
      let typeName = e.target.dataset.name;
      let userId = e.target.dataset.uid;
      let phone = e.target.dataset.phone;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        userIndex,
        userId,
        typeName,
        phone,
        type_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.monthId,this.data.phone,,this.data.userId]
      this.triggerEvent('myevent', idArray)
    },
    setmonth: function (e) {
      console.log(e)
      this.setData({
        inputName: ''
      })
      let monthIndex = e.target.dataset.index; //当前点击的索引
      let monthName = e.target.dataset.monthName;
      let monthId = e.target.dataset.monthId;
      let userId = e.target.dataset.uid;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        monthIndex,
        monthId,
        userId,
        monthName,
        month_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.monthId,this.data.phone,this.data.userId]
      this.triggerEvent('myevent', idArray)
    },
    cancelSelect: function(){
      this.pickUp()
      this.setData({
        cityShow: '0'
      })
    },
    pickUp: function(){
      if (this.data.cityShow == '1') {
        this.toggleAnimation(0)
        this.setData({
          prov_animationData: this.animation.export()
        })
      } else if (this.data.cityShow == '2') {
        this.toggleAnimation(0)
        this.setData({
          city_animationData: this.animation.export()
        })
      } else if (this.data.cityShow == '3') {
        this.toggleAnimation(0)
        this.setData({
          month_animationData: this.animation.export()
        })
      } else if (this.data.cityShow == '4') {
        this.toggleAnimation(0)
        this.setData({
            type_animationData: this.animation.export()
        })
      }
    }
  }
})